package com.example.easyhttp;

import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

public class LogUtils {


    private static HiLogLabel hiLogLabel = new HiLogLabel(HiLog.LOG_APP, 0, "===chants log===");

    /**
     * 调试信息
     */
    public static void d(String tag, Object... objects) {
            HiLog.debug(hiLogLabel, tag+ getObjectsString(objects));
    }

    /**
     * 常规信息
     */
    public static void i(String tag, Object... objects) {
            HiLog.info(hiLogLabel, tag+ getObjectsString(objects));
    }

    /**
     * 警告类信息
     */
    public static void w(String tag, Object... objects) {
            HiLog.warn(hiLogLabel, tag+ getObjectsString(objects));
    }

    /**
     * 异常类信息
     */
    public static void e(String tag, Object... objects) {
            HiLog.error(hiLogLabel, tag + getObjectsString(objects));
    }

    /**
     * 重大级别的信息
     */

    public static void f(String tag, Object... objects) {
            HiLog.fatal(hiLogLabel, tag+ getObjectsString(objects));
    }

    private static String getObjectsString(Object... objects) {
        if (objects == null || objects.length == 0) {
            return "";
        }
        if (objects.length > 1) {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("\n");
            for (int i = 0; i < objects.length; i++) {
                Object object = objects[i];
                if (object == null) {
                    stringBuilder.append("Param").append("[").append(i).append("]").append(" = ").append("null").append("\n");
                } else {
                    stringBuilder.append("Param").append("[").append(i).append("]").append(" = ").append(object.toString()).append("\n");
                }
            }
            return stringBuilder.toString();
        } else {
            Object object = objects[0];
            return object == null ? "null" : object.toString();
        }
    }

}
